//引模块
require("../../assets/css/index.less");
require("../../assets/fonts/iconfont.css");
//引当前模块
require("./mybadge.less");
//引入公共js模块
let dom = require("../../utils/dom.js");
let https = require("../../utils/https.js");

// dom.getEle("header").addEventListener("click", function () {
//
// })

let newdata = [
  require("../../assets/imgs/mybadge01.jpg"),
  require("../../assets/imgs/mybadge02.jpg"),
  require("../../assets/imgs/mybadge03.jpg"),
  require("../../assets/imgs/mybadge04.jpg"),
  require("../../assets/imgs/mybadge05.jpg"),
  require("../../assets/imgs/mybadge06.jpg"),
  require("../../assets/imgs/mybadge07.jpg"),
  require("../../assets/imgs/mybadge08.jpg"),
  require("../../assets/imgs/mybadge09.jpg"),
];
dom.ready(function () {
  function getUserInfo() {
    //发送ajax获取个人信息
    https.get("/api/user/info", (res) => {
      //判定
      if (res.errno == 0) {
        //解构数据
        let { ranking } = res.data;
        //1.渲染数据到页面的指定位置
        dom.$(".num").innerHTML = ranking;
        //2.把最新用户信息存储到本地
        local.set("user", res.data);
      }
    });
  }
  getUserInfo();
  https.get("/api/exercise/badge", (res) => {
    res.data.forEach((v) => {
      dom.getEle("#main").innerHTML += `
    <div>
    <img src="${newdata[v.id]}" alt="" width="90">
        </div>
    `;
    });
  });

  dom.getEle("header").addEventListener("click", function () {
    location.href = "myhome.html";
  });
});
